package com.xuecheng.media.controller;

import com.xuecheng.api.media.MediaApi;
import com.xuecheng.api.media.model.dto.MediaDTO;
import com.xuecheng.api.media.model.qo.QueryMediaModel;
import com.xuecheng.api.media.model.vo.MediaAuditVo;
import com.xuecheng.api.media.model.vo.MediaVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.media.convert.MediaConvert;
import com.xuecheng.media.service.MediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
public class MediaController implements MediaApi {


    @Autowired
    private MediaService mediaService;


    //保存媒资信息
    @PostMapping("/media")
    public MediaDTO saveMedia(@RequestBody MediaVO mediaVO) {

        Long companyId = SecurityUtil.getCompanyId();

        //vo转dto
        MediaDTO mediaDTO = MediaConvert.INSTANCE.vo2dto(mediaVO);

        mediaDTO.setCompanyId(companyId);

        //调用service保存方法
        MediaDTO result = mediaService.saveMedia(mediaDTO);

        //返回结果
        return result;
    }


    //查询媒资信息
    @PostMapping("/media/list")
    public PageVO queryMediaList(PageRequestParams params, @RequestBody QueryMediaModel model) {

        Long companyId = SecurityUtil.getCompanyId();


        return mediaService.queryMediaList(params,model,companyId);
    }

    //预览媒资
    @GetMapping("/media/preview/{mediaId}")
    public String previewMedia(@PathVariable Long mediaId) {

        Long companyId = SecurityUtil.getCompanyId();

        return mediaService.previewMedia(mediaId,companyId);
    }

    //删除媒资
    @DeleteMapping("media/{mediaId}")
    public void deleteMedia(@PathVariable Long mediaId) {

        Long companyId = SecurityUtil.getCompanyId();

        mediaService.deleteMedia(mediaId,companyId);

    }

    //根据id查询媒资信息
    @GetMapping("/l/media/{mediaId}")
    public RestResponse<MediaDTO> queryMediaById(@PathVariable Long mediaId) {


        return mediaService.queryMediaById(mediaId);
    }

    //运营平台查询媒资信息
    @PostMapping("/m/media/list")
    public PageVO RunQueryMediaList(PageRequestParams params, @RequestBody QueryMediaModel model) {


        return mediaService.queryMediaList(params,model,null);
    }

    //运营平台预览媒资
    @GetMapping("/m/media/preview/{mediaId}")
    public String RunPreviewMedia(@PathVariable Long mediaId) {

        Long companyId = SecurityUtil.getCompanyId();


        return mediaService.previewMedia(mediaId,companyId);
    }


    //运营平台审核媒资
    @PutMapping("/m/media/audit")
    public void modifyCourseAudit(@RequestBody MediaAuditVo mediaAuditVo) {

        mediaService.modifyMediaAudit(mediaAuditVo);
    }


}
